import * as API from '@/api/dataBoard';
import { ref, reactive, onBeforeMount, watch, } from 'vue';
const getMax = (_data: any) => {
  let total = 0;
  _data.forEach((item: any) => {
    total += item.value;
  });
  return total;
}
export default () => {
  const thisMonthData = reactive({
    water: {},
    gas: {},
    elec: {}
  });
  const lastMonthData = reactive({
    water: null,
    gas: null,
    elec: null
  });
  const fuData = ref([]);
  const production = reactive({
    rate: null,
    month: null,
    history: null
  })
  const getThisMonth = async () => {
    const res = await API.getThisMonth();
    if (res) {
      thisMonthData.water = res.monthDosageVoMap['水'];
      thisMonthData.elec = res.monthDosageVoMap['电'];
      thisMonthData.gas = res.monthDosageVoMap['天燃气'];
    }
  }
  const getLastMonth = async () => {
    const res = await API.getLastMonth();
    if (res) {
      lastMonthData.water = res['水'];
      lastMonthData.elec = res['电'];
    }
  }
  const getLastMonthGas = async () => {
    const res = await API.getLastMonthGas();
    if (res) {
      lastMonthData.gas = res;
    }
  }
  const getFu = async () => {
    const res = await API.getFu();
    if (res) {
      fuData.value = res;
    }
  }
  const getDateMonthRateCount=async () => {
    const res = await API.getDateMonthRateCount();
    if (res) {
      production.rate = res;
    }
  }
  const getDateMonthCount=async () => {
    const res = await API.getDateMonthCount();
    if (res) {
      production.month = res;
    }
  }
  const getDateHisCount=async () => {
    const res = await API.getDateHisCount();
    if (res) {
      production.history = res;
    }
  }
  onBeforeMount(() => {
    // getThisMonth();
    // getLastMonth();
    // getLastMonthGas();
    getFu();
    // getDateMonthRateCount();
    // getDateMonthCount();
    // getDateHisCount();
  })
  return {
    thisMonthData,
    lastMonthData,
    fuData,
    production
  }
}